<?php
//eval ($thfr_css['customphp']);

function tf_pagetemplate_include($thisTemplate, $body_class) {
  global $thfr_css;

  eval ("echo ('<style type=\"text/css\">" . $thfr_css['customcss'] . "</style>');");
  ?>
<script type="text/javascript">
  var usedcolors = new Array();
  jQuery.getJSON(THFRURL + "ajax.php", function (json) {
    jQuery.each(json, function (key, val) {
      usedcolors.push(val);
    });
  });
</script>
<div class="<?php echo ($thisTemplate == 'index' ? 'index' : 'index ' . $thisTemplate); ?>" selector="<?php echo ($thisTemplate == 'index' ? 'div.index' : trim($body_class)); ?>" style="position: relative;">
  <?php
  echo tf_get_template_include_layout($thisTemplate, $body_class);
  ?>

</div><!-- / div.body -->
<?php
}

function tf_get_template_include_layout($thisTemplate, $body_class) {
  $aSelectors = array(
    'selector_container' => ' selector="' . $body_class . 'div#container"',
    'content' => tf_get_template_include_content($thisTemplate, $body_class),
    'left' => tf_get_template_include_left($thisTemplate, $body_class),
    'right' => tf_get_template_include_right($thisTemplate, $body_class),
    'header' => tf_get_template_include_header($thisTemplate, $body_class),
    'footer' => tf_get_template_include_footer($thisTemplate, $body_class),
  );
  return tf_common_template_layout($thisTemplate, $aSelectors);
}

function tf_get_template_include_header($thisTemplate, $body_class) {
  $aSelectors = array(
    'selector_td_header' => ' selector="' . $body_class . 'div#td-header"',
    'body' => tf_drop_area($thisTemplate, "header", $body_class),
  );
  return tf_common_template_header_section($aSelectors);
}

function tf_get_template_include_footer($thisTemplate, $body_class) {
  $aSelectors = array(
    'selector_td_footer' => ' selector="' . $body_class . 'div#td-footer"',
    'body' => tf_drop_area($thisTemplate, "footer", $body_class),
  );
  return tf_common_template_footer_section($aSelectors);
}

function tf_get_template_include_left($thisTemplate, $body_class) {
  $aContents = array(
    'selector_td_left' => ' selector="' . $body_class . 'div#td-left"',
    'selector_td_left3' => ' selector="' . $body_class . 'div#td-left3"',
    'selector_div_left3' => ' selector="' . $body_class . 'div#div-left3"',
    'selector_td_left1' => ' selector="' . $body_class . 'div#td-left1"',
    'selector_div_left1' => ' selector="' . $body_class . 'div#div-left1"',
    'selector_td_left2' => ' selector="' . $body_class . 'div#td-left2"',
    'selector_div_left2' => ' selector="' . $body_class . 'div#div-left2"',
    'sidebar_left3' => tf_get_template_include_widget_example($body_class) . tf_get_template_include_widget_w_link_example($body_class),
    'sidebar_left1' => tf_get_template_include_widget_w_link_example($body_class) . tf_get_template_include_widget_example($body_class),
    'sidebar_left2' => tf_get_template_include_widget_example($body_class) . tf_get_template_include_widget_w_link_example($body_class),
    'drop_area_beforeSidebarLeft' => tf_drop_area($thisTemplate, "beforeSidebarLeft", $body_class),
    'drop_area_afterSidebarLeft' => tf_drop_area($thisTemplate, "afterSidebarLeft", $body_class),
  );
  return tf_common_template_left_section($aContents);
}

function tf_get_template_include_right($thisTemplate, $body_class) {
  $aContents = array(
    'selector_td_right' => ' selector="' . $body_class . 'div#td-right"',
    'selector_td_right3' => ' selector="' . $body_class . 'div#td-right3"',
    'selector_div_right3' => ' selector="' . $body_class . 'div#div-right3"',
    'selector_td_right1' => ' selector="' . $body_class . 'div#td-right1"',
    'selector_div_right1' => ' selector="' . $body_class . 'div#div-right1"',
    'selector_td_right2' => ' selector="' . $body_class . 'div#td-right2"',
    'selector_div_right2' => ' selector="' . $body_class . 'div#div-right2"',
    'sidebar_right3' => tf_get_template_include_widget_w_link_example($body_class) . tf_get_template_include_widget_example($body_class),
    'sidebar_right1' => tf_get_template_include_widget_w_link_example($body_class) . tf_get_template_include_widget_example($body_class),
    'sidebar_right2' => tf_get_template_include_widget_example($body_class) . tf_get_template_include_widget_w_link_example($body_class),
    'drop_area_beforeSidebarRight' => tf_drop_area($thisTemplate, "beforeSidebarRight", $body_class),
    'drop_area_afterSidebarRight' => tf_drop_area($thisTemplate, "afterSidebarRight", $body_class),
  );
  return tf_common_template_right_section($aContents);
}

function tf_get_template_include_content($thisTemplate, $body_class) {

  $body = tf_drop_area($thisTemplate, "centerTop", $body_class);
  $body .= tf_postcontainer_preview($thisTemplate, $body_class);
  if ($thisTemplate == 'single') {
    $body .= '<div style="clear: both;"></div>' . tf_drop_area($thisTemplate, "centerBeforeComments", $body_class);
    $body .= '<div id="comments_block" selector="div#comments_block">
  <div style="padding:20px;border:solid 1px black;background:yellow"><strong>comments.php</strong> (see tab "comments") will be included here ...</div></div>';
  }

  // No second post for single and page templates
  if (!in_array($thisTemplate, array('page', 'single'))) {
    $body .= tf_postcontainer_preview($thisTemplate, $body_class);
  } else { // no second post for single & page
    //$body .= tf_drop_area($thisTemplate, "centerBottom", $body_class);
  }
  $body .= '<div style="clear: both;"></div>' . tf_drop_area($thisTemplate, "centerBottom", $body_class);

  $aContents = array(
    'selector_td_center' => ' selector="' . $body_class . 'div#td-center"',
    'body' => $body,
  );
  return tf_common_template_content_section($aContents);
}

?>
